package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JBDCDemo7 {
    public static void main(String[] args) {
        try (
                Connection connection=DBUtil.getConnection();//获取数据库连接
        ){
            //查看1年级1班的学生有多少人
            Statement statement = connection.createStatement();//创建Statement对象
            String sql = "SELECT COUNT(*) count "+
                         "FROM student s,class c "+
                         "WHERE s.class_id=c.id "+
                         "AND c.name='1年级1班'";
            ResultSet rs = statement.executeQuery(sql);//执行SQL语句

            if (rs.next()){
//                int count = rs.getInt("count(*)");
                int count = rs.getInt("count");
                System.out.println("人数："+count);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
